

use std::collections::HashMap;

lazy_static::lazy_static! { 
    static ref CLIENT:reqwest::blocking::Client = reqwest::blocking::Client::new();
}


pub fn get(url: &str) -> Option<reqwest::blocking::Response>
{
    let result = reqwest::blocking::get(url);
    match result
    {
        Result::Ok(response)=> Option::Some(response),
        Result::Err(_e)=> Option::None
    }
}


pub type Parameter = (String, String);
pub type Parameters = HashMap<String, String>;

trait ParametersMethods
{
    fn insert_parameter(&mut self, parameter:Parameter);
}

impl ParametersMethods for Parameters
{
    fn insert_parameter(&mut self, parameter:Parameter)
    {
        self.insert(parameter.0, parameter.1);
    }
}

pub fn post(url: &str, args:&Parameters) -> Option<reqwest::blocking::Response>
{
    let builder = CLIENT.post(url);
    let result = builder.form(args).send();

    match result
    {
        Result::Ok(response) => Option::Some(response),
        Result::Err(_e) => Option::None
    }
}



